package com.ssy.lingxi.logistics.controller.mobile;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.logistics.model.request.LogisticsOrderRequest;
import com.ssy.lingxi.logistics.model.request.OrderIdOrCodeRequest;
import com.ssy.lingxi.logistics.model.response.LogisticsOrderResponse;
import com.ssy.lingxi.logistics.service.ILogisticsOrderService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @menu APP - 换货申请 - 待新增物流单
 * @author yzc
 * @version 2.0.0
 * @date 2020/7/10
 */
@RestController
@RequestMapping("/logistics/mobile/orderWaitSubmit")
public class MobileLogisticsOrderWaitSubmitController extends BaseController {

    @Resource
    private ILogisticsOrderService logisticsOrderService;

    /**
     * 物流单查询
     * @param request 接口参数
     * @return 返回结果
     */
    @GetMapping(value = "/get")
    public Wrapper<LogisticsOrderResponse> getLogisticsOrder(OrderIdOrCodeRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();

        //参数校验
        if (Objects.isNull(request.getId()) && Objects.isNull(request.getCode())) {
            return Wrapper.fail("id或编号不能为空");
        }
        return logisticsOrderService.getSupplierLogisticsOrder(request, sysUser);
    }

    /**
     * 物流单添加
     * @param request 接口参数
     * @return 返回结果
     */
    @PostMapping(value = "/add")
    public Wrapper<Void> addLogisticsOrder(@RequestBody @Validated(LogisticsOrderRequest.Add.class) LogisticsOrderRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return logisticsOrderService.addLogisticsOrder(request, sysUser);
    }

    /**
     * 物流单修改
     * @param request 接口参数
     * @return 返回结果
     */
    @PostMapping(value = "/update")
    public Wrapper<Void> updateLogisticsOrder(@RequestBody @Validated(LogisticsOrderRequest.Update.class) LogisticsOrderRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return logisticsOrderService.updateLogisticsOrder(request, sysUser);
    }

}
